package com.citywithincity.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.citywithincity.db.interfaces.IDataSourceProvider;

public class RawDataSource implements IDataSourceProvider {
	private ConnectionDescription description;
	public RawDataSource(ConnectionDescription cd) {
		this.description = cd;
		try{
			Class.forName(cd.getDriverClass());
		}catch(Exception e){
			throw new RuntimeException(e);
		}
	}


	@Override
	public void close() {
		
	}

	

	@Override
	public Connection getConnection() throws SQLException {
		return DriverManager.getConnection(description.getJdbcUrl(), description.getUser(), description.getPassword());
	}


	@Override
	public ArFactory createArFactory() throws SQLException {
		return description.create(this);
	}


	@Override
	public void close(Connection connection) {
		try {
			connection.close();
		} catch (Throwable e) {
			
		}
	}
	
	

}
